/**
 * Created by hxpeng on 2017/3/24.
 */
(function () {
    'use strict';

    angular.module('App.pages.class.msg')
        .controller('NewTextMsgCtrl', NewTextMsgCtrl);

    function NewTextMsgCtrl($scope,$stateParams,AppUtils,MsgModel,$state) {

        var vm = this;
        vm.msgInfo = {};
        vm.msgInfo.msgType = "text";
        vm.msgInfo.studentIds = $stateParams.studentArray;
        if(AppUtils.isUndefinedOrNull($stateParams.studentArray) || vm.msgInfo.studentIds.length < 1){
            AppUtils.showAlert("请选择宝宝留言");
            AppUtils.goBack();
        }

        $scope.saveMsgInfo = function(){
            if(AppUtils.isUndefinedOrNull(vm.msgInfo.msgContent)){
                AppUtils.showAlert("请输入留言内容！");
                return false;
            }
            MsgModel.createNewMsg(vm.msgInfo).$promise.then(function(response){
                var result = response.result;
                if(!AppUtils.isUndefinedOrNull(result) && result == 'success'){
                    AppUtils.showAlert("留言成功！");
                    $state.go("classMenu.teacherIndex");
                }else{
                    AppUtils.showAlert(response.msg);
                }
            })
        }
    }
})();
